<?php


namespace app\shopConsole\service\user;

use app\dao\user\ShopUserDao;
use app\model\ShopUser;

class UserService
{
    /**
     * @var ShopUser
     */
    private ShopUser $shopUser;

    public function __construct(ShopUser $shopUser)
    {
        $this->user = $shopUser ;
    }

    public function ban()
    {
        $shopUserDao = new ShopUserDao();
        $shopUserDao->update(['is_ban' => 1], $this->user->id);
        return $shopUserDao->getById($this->user->id);
    }

    public function undo()
    {
        $shopUserDao = new ShopUserDao();
        $shopUserDao->update(['is_ban' => 0], $this->user->id);
        return $shopUserDao->getById($this->user->id);
    }

    public function updateUserTags($tagJson)
    {
        $tags = '';
        foreach ($tagJson as $value)
        {
            $tags = $tags . $value . ',';
        }

        $updateList = [
            'tags' => substr($tags, 0, strlen($tags) - 1),
        ];

        $shopUserDao = new ShopUserDao();
        $shopUserDao->update($updateList, $this->user->id);
        return $shopUserDao->getById($this->user->id);
    }

}